package org.xtremeobjects.domain.party;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.xtremeobjects.anotations.ddd.Repository;
import org.xtremeobjects.domain.hibernate.HibernateRepository;
import org.xtremeobjects.domain.hibernate.HibernateSession;
import org.xtremeobjects.domain.role.PartyRole;

import com.google.inject.Inject;

@Repository(root=Party.class)
public class PartyRepositoryHibernate extends HibernateRepository<Party, String> implements PartyRepository {

	@Inject
	public PartyRepositoryHibernate( HibernateSession session ) {
		super(session);
	}

	public List<Party> findPartyByNameLike(String name) {
		return getSession().createCriteria(Party.class).add(Restrictions.like("name", "%" + name + "%")).list();
	}

	public List<PartyRole> findRolesByParty(Party party) {
		return getSession().createCriteria(PartyRole.class).add(Restrictions.eq("party", party)).list();
	}

}
